﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsApp
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            textBox1.Text = LogHelper.Log.LogConfigPath;
        }

        private void log(int i)
        {
            LogHelper.Log.Debug(new MyLogContent(i.ToString(), i.ToString()));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int num = int.Parse(textBox2.Text);
            ThreadStart t = new ThreadStart(new Action(() =>
            {
                Parallel.For(0, num, (i) =>
                {
                    log(i);
                });
            }));
            Stopwatch watch = new Stopwatch();
            watch.Start();
            Thread thr = new Thread(t);
            thr.Start();
            while (true)
            {
                if (thr.ThreadState == System.Threading.ThreadState.Stopped)
                {
                    watch.Stop();
                    break;
                }
            }

            textBox1.Text = "耗时：" + watch.ElapsedMilliseconds.ToString() + "毫秒";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();
            for (int i = 1; i <= int.Parse(textBox3.Text); i++)
            {
                log(i);
            }
            watch.Stop();
            textBox1.Text = "耗时：" + watch.ElapsedMilliseconds.ToString() + "毫秒";
        }
    }
}
